//
//  LanchViewController.m
//  SnacksOfChina
//
//  Created by qianfeng on 15/9/14.
//  Copyright (c) 2015年 AD Wang. All rights reserved.
//

#import "LanchViewController.h"
#import "TabBarViewController.h"

#define kCellId @"UICollectionViewCell"

@interface LanchViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic ,strong) UICollectionView * collectionView;
@property(nonatomic ,strong) NSMutableArray * dataArr;

@end

@implementation LanchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createCollectionView];
}

#pragma mark - UICollectionview
- (void)createCollectionView
{
    self.dataArr = [[NSMutableArray alloc]initWithObjects:@"help1",@"help2",@"help3",@"help4",@"help5", nil];
    //UICollectionView的布局，都要依赖于layout
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
    //所有cell的大小 屏幕大小
    layout.itemSize = kScreenSize;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenSize.width, kScreenSize.height) collectionViewLayout:layout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    
    [self.view addSubview:self.collectionView];
    //注册cell 需要 注册
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:kCellId];
    //按页滚动
    self.collectionView.pagingEnabled = YES;
}
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellId forIndexPath:indexPath];
    cell.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed: self.dataArr[indexPath.row]]];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == self.dataArr.count - 1) {
#if 0
        TabBarViewController * tab = [[TabBarViewController alloc]init];
        [self presentViewController:tab animated:YES completion:nil];
#else
        TabBarViewController * tab = [[TabBarViewController alloc]init];
        UIWindow * window = [[UIApplication sharedApplication]keyWindow];
        
        window.rootViewController = tab;
#endif
        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   
}



@end








